package sqlTestes.tForeignKey;

import java.util.ArrayList;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import sql.ddl.PrimaryKey;
import sql.ddl.Tabela;
import sql.ddl.coluna.Coluna;
import sql.ddl.coluna.ForeignKey;

public class TesteForeingKey implements Especificacao {
	ForeignKey a = null;

	ForeignKey as = null;

	@Before
	public void up() throws Exception {
		Tabela b = new Tabela("B");
		b.setPrimaryKey(new PrimaryKey(new Coluna("Int4", "a")));
		a = new ForeignKey(b, new Coluna[] { new Coluna("INTEGER", "a") });
	}

	@Test
	public void codigoSQLColunaINTEGERaReferenciaColunaATabelaB() {
		Assert.assertEquals("FOREIGN KEY(a)REFERENCES B(a)", a.codigoSQL());
	}

	@Test
	public void codigoSQLColunaINTEGERa_bReferenciaColunaA_BTabelaB() {
		ArrayList<Coluna[]> refe2 = new ArrayList<Coluna[]>();
		refe2.add(new Coluna[] { new Coluna("INTEGER", "a", false),
				new Coluna("INTEGER", "a", false) });
		refe2.add(new Coluna[] { new Coluna("INTEGER", "b", false),
				new Coluna("INTEGER", "c", false) });
		as = new ForeignKey(new Tabela("B"), refe2);

		Assert
				.assertEquals("FOREIGN KEY(a,b)REFERENCES B(a,c)", as
						.codigoSQL());
	}

	@Test
	public void codigoSQLColunaINTEGERaReferenciaColunaATabelaBConstraint_AGUA() {
		a.setConstraint("agua");
		Assert.assertEquals("CONSTRAINT agua FOREIGN KEY(a)REFERENCES B(a)", a
				.codigoSQL());

	}

}
